//
//  CarouselViewCollectionViewCell.m
//  MyFramework
//
//  Created by 余洋 on 2018/9/13.
//  Copyright © 2018年 余洋. All rights reserved.
//

#import "CarouselViewCollectionViewCell.h"
#import "CarouselView.h"

#import <Masonry.h>

@interface CarouselViewCollectionViewCell()<CarouselViewDelegate>

@end

@implementation CarouselViewCollectionViewCell

@synthesize picArray = _picArray;

- (void)createUI {
    CarouselView *carouselView = [[[NSBundle mainBundle] loadNibNamed:@"CarouselView" owner:nil options:nil] firstObject];
    [self addSubview:carouselView];
    [carouselView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self);
        make.right.mas_equalTo(self);
        make.top.mas_equalTo(self);
        make.bottom.mas_equalTo(self);
    }];
    NSMutableArray *imageArray = [NSMutableArray array];
    for (int i = 0; i < _picArray.count; i++) {
        NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:_picArray[i]]];
        UIImage *image = [[UIImage alloc] initWithData:data];
        [imageArray addObject:image];
    }
    carouselView.picUrlArray = imageArray;
    carouselView.contentMode = UIViewContentModeScaleAspectFill;
    carouselView.delegate = self;
}

- (void)setPicArray:(NSMutableArray *)picArray {
    if (picArray) {
        _picArray = picArray;
        [self createUI];
    }
}

#pragma mark - CarouselViewDelegate
- (void)clickImage:(NSInteger)index {
    NSLog(@"点击了第%ld张图片",index);
}
@end
